package com.xjtu.platform.security.curr_user;

import com.xjtu.platform.common.CommonService;
import com.xjtu.platform.common.CurrentUser;
import com.xjtu.platform.common.Result;
import com.xjtu.platform.common.TokenUtils;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @创建人 MBY381
 * @创建时间 2022/6/30 09:15
 * @描述 暂无
 */


@RestController
@RequestMapping("/curr_user")
public class CurrentUserAPI {

    @Resource
    private CommonService commonService;


    @RequestMapping(value = "/get_curr-user",method = RequestMethod.GET)
    public Result getCurr_User(@RequestHeader("Token") String Token){
        if(Token == null){
            System.out.println("查询当前用户时无令牌");
        }
        try {
            CurrentUser currentUser = TokenUtils.getUserInfo(Token, commonService);
            return Result.success("查询成功", currentUser);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.fail(400,"查询当前用户失败！");
    }
}
